<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    html,body{
        width: 100%;
        margin:0;
        padding: 0;
    }
    .content{
        width: 740px;
        height:200px;
       border: 1px solid black
    }
    #box{
        width: 100px;
        height: 200px;
       border: 1px solid black;
       background:black;
    }
    .a{
      position: fixed;
      top:0;
    }
    </style>
</head>
<body>
    <div class="content"></div>
    <div class="content">
    <div  id="box"></div>
     </div>
    <div class="content"></div>
    <div class="content"></div>
    <div class="content"></div>
    <div class="content"></div>
    <div class="content"></div>
    <div class="content"></div>
    <script>
         var scrollTop=document.getElementById("box")
         console.log(scrollTop)
        window.onscroll=function (){ 
        var scroll=document.documentElement.scrollTop;
        console.log(scroll)
      if(scroll>200){
        scrollTop.style.position="fixed";
        scrollTop.style.top=0;
      }
      else{
        scrollTop.style.position="static";
      }
     }
    </script>
</body>
</html>